
/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func deleteDuplication(head *ListNode) *ListNode {
	var arr []int = make([]int, 0)
	b := head
	for {
		if b == nil {
			break
		} else {
			arr = append(arr, b.Val)
			b = b.Next
		}
	}

	if len(arr) == 0 {
		return nil
	} else {
		var list []int = make([]int, 0)
		for i := 0; i < len(arr)-1; i++ {
			for j := i + 1; j < len(arr); j++ {
				if arr[i] == arr[j] {
					list = append(list, arr[i])
				}
			}
		}

		for i := 0; i < len(list); i++ {
			for j := 0; j < len(arr); j++ {
				if list[i] == arr[j] {
					if j == 0 {
						if len(arr) == 1 {
							arr = make([]int, 0)
						} else {
							arr = arr[1:]
							j--
						}
					} else if j == len(arr)-1 {
						arr = arr[:len(arr)-1]
						j--
					} else {
						arr = append(arr[:j], arr[j+1:]...)
						j--
					}
				}
			}
		}
	}

	var list []ListNode = make([]ListNode, 0)
	if len(arr) == 0 {
		return nil
	}
	for i := 0; i < len(arr); i++ {
		var node ListNode
		node.Val = arr[i]
		node.Next = &node
		list = append(list, node)
	}
	for i := 0; i < len(arr); i++ {
		if i != len(arr)-1 {
			list[i].Next = &list[i+1]
		} else {
			list[i].Next = nil
		}
	}
	return &list[0]
}